package tech.summerly.weather.model

import android.net.Uri
import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.util.Util
import tech.summerly.weather.AppContext
import tech.summerly.weather.util.Position

data class LiveWeatherSource(
        val id: String,
        val name: String,
        val uri: String,
        val position: Position
) {

    /**
     * the media source to play
     */
    val mediaSource: MediaSource
        get() = ExtractorMediaSource.Factory(sourceFactory).createMediaSource(Uri.parse(uri))

    companion object {

        private val sourceFactory by lazy {
            DefaultDataSourceFactory(
                    AppContext.instance,
                    Util.getUserAgent(AppContext.instance, ""),
                    DefaultBandwidthMeter())
        }
    }

}